
Imports cmplib01



Public Class frmAssignRules
    Private c_MODULE As String = "frmAssignRules"
    '// used to assign rules to a chitmember

    Private _objective As GroundChitType
    Private _token As TokenType
    Private bUsingToken As Boolean = False

    Private _game As CampaignerGameData

    Public Sub New(ByRef obj As GroundChitType, ByRef ptrGame As CampaignerGameData)
        InitializeComponent()
        _objective = obj
        _game = ptrGame

        ListAvailableRules()
        ListExistingRules()

    End Sub

    Public Sub New(ByRef obj As TokenType, ByRef ptrGame As CampaignerGameData)
        InitializeComponent()

        _token = obj
        _game = ptrGame

        bUsingToken = True

        ListAvailableRules()
        ListExistingRules()

    End Sub


    Private Sub ListAvailableRules()
        Try
            For Each key As String In _game.RuleTypes_g.HT.Keys
                lstAvailable.Items.Add(_game.RuleTypes_g.Item(key))
            Next
        Catch ex As Exception
            HandleException(c_MODULE, ex)
        End Try
    End Sub

    Private Sub ListExistingRules()
        Try
            Dim usingRules As Rules2

            If bUsingToken Then
                usingRules = _token.TokenRules
            Else
                usingRules = _objective.GCRules
            End If

            For Each rult As RuleType In usingRules
                lstSelected.Items.Add(rult)
            Next
        Catch ex As Exception
            HandleException(c_MODULE, ex)
        End Try
    End Sub



 
    Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click
        If lstSelected.SelectedItem Is Nothing Then Exit Sub

        Try
            Dim usingRules As Rules2

            If bUsingToken Then
                usingRules = _token.TokenRules
            Else
                usingRules = _objective.GCRules
            End If

            usingRules.Remove(lstSelected.SelectedItem)
            lstSelected.Items.Remove(lstSelected.SelectedItem)

        Catch ex As Exception
            HandleException(c_MODULE, ex)
        End Try
    End Sub

    Private Sub btnRemoveAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemoveAll.Click

        Try
            Dim usingRules As Rules2

            If bUsingToken Then
                usingRules = _token.TokenRules
            Else
                usingRules = _objective.GCRules
            End If

            usingRules.Clear()
            lstSelected.Items.Clear()
        Catch ex As Exception
            HandleException(c_MODULE, ex)
        End Try

    End Sub

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        Me.Hide()
    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        If lstAvailable.SelectedItem Is Nothing Then Exit Sub

        Try
            Dim usingRules As Rules2
            If bUsingToken Then
                usingRules = _token.TokenRules
            Else
                usingRules = _objective.GCRules
            End If
            usingRules.Add(lstAvailable.SelectedItem)
            lstSelected.Items.Add(lstAvailable.SelectedItem)

        Catch ex As Exception

        End Try
    End Sub
End Class